package com.itheima.config;

import com.itheima.interceptor.DemoInterceptor;
import com.itheima.interceptor.TokenInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Description: WebConfig 配置类
 * @Author: HH
 * @Date: 2025/4/20 16:05
 **/
@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    private DemoInterceptor demoInterceptor;
    @Autowired
    private TokenInterceptor tokenInterceptor;

    // 配置拦截器，指定拦截器拦截所有请求
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //注册自定义拦截器对象
        // registry.addInterceptor(demoInterceptor) // 添加拦截器
        //         .addPathPatterns("/**"); // 添加拦截路径，/* 为拦截所有请求
        registry.addInterceptor(tokenInterceptor) // 添加拦截器
                .addPathPatterns("/**") // 添加拦截路径，/** 为拦截所有请求
                .excludePathPatterns("/login"); // 排除拦截路径，/login 为排除登录请求
    }
}
